package com.sj.purchase.modules.cost.domain.order;

import com.sj.purchase.modules.cost.domain.WarehouseEnum;
import com.sj.purchase.util.StockUtils;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by 宋开宗 on 2017/7/27 0027.
 */
@Entity
@Table(name = "t_adjust_order")
public class AdjustOrder {
    @Id
    private String id;
    private String adjustmentNo;
    private String skuNo;
    private Integer adjustedQty;
    private String createUser;
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate;

    @Transient
    private String warehouseName;

    private WarehouseEnum warehouseEnum;

    public AdjustOrder() {
    }

    public AdjustOrder(String id, String adjustmentNo, String skuNo, Integer adjustedQty, String createUser, Date createDate, WarehouseEnum warehouseEnum) {
        this.id = id;
        this.adjustmentNo = adjustmentNo;
        this.skuNo = skuNo;
        this.adjustedQty = adjustedQty;
        this.createUser = createUser;
        this.createDate = createDate;
        this.warehouseEnum = warehouseEnum;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public AdjustOrder setCreateDate(Date createDate) {
        this.createDate = createDate;
        return this;
    }

    public String getId() {
        return id;
    }

    public AdjustOrder setId(String id) {
        this.id = id;
        return this;
    }

    public String getAdjustmentNo() {
        return adjustmentNo;
    }

    public AdjustOrder setAdjustmentNo(String adjustmentNo) {
        this.adjustmentNo = adjustmentNo;
        return this;
    }

    public String getSkuNo() {
        return skuNo;
    }

    public AdjustOrder setSkuNo(String skuNo) {
        this.skuNo = skuNo;
        return this;
    }

    public Integer getAdjustedQty() {
        return adjustedQty;
    }

    public AdjustOrder setAdjustedQty(Integer adjustedQty) {
        this.adjustedQty = adjustedQty;
        return this;
    }

    public String getCreateUser() {
        return createUser;
    }

    public AdjustOrder setCreateUser(String createUser) {
        this.createUser = createUser;
        return this;
    }

    public String getWarehouseName() {
        return warehouseName;
    }

    public AdjustOrder setWarehouseName(String warehouseName) {
        this.warehouseName = warehouseName;
        setWarehouseEnum(StockUtils.getWarehouse(warehouseName));
        return this;
    }

    public WarehouseEnum getWarehouseEnum() {
        return warehouseEnum;
    }

    public AdjustOrder setWarehouseEnum(WarehouseEnum warehouseEnum) {
        this.warehouseEnum = warehouseEnum;
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AdjustOrder order = (AdjustOrder) o;

        return id != null ? id.equals(order.id) : order.id == null;
    }


    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "AdjustOrder{" +
                "id=" + id +
                ", adjustmentNo='" + adjustmentNo + '\'' +
                ", skuNo='" + skuNo + '\'' +
                ", adjustedQty=" + adjustedQty +
                ", createUser='" + createUser + '\'' +
                ", createDate=" + createDate +
                '}';
    }
}
